package com.WhatsUp.tools;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.content.Context;

public class FileHelper {
	public static String ReadSettings(Context context, String file) {
		FileInputStream fIn = null;
		BufferedReader isr = null;

		String con = null;

		try {
			fIn = context.openFileInput(file);
			isr = new BufferedReader(new InputStreamReader(fIn));
			con = isr.readLine();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				isr.close();
				fIn.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return con;
	}

	public static boolean WriteSettings(Context context , String file , String data) {
		FileOutputStream fOut = null;
		OutputStreamWriter osw = null;
		
		boolean flag = true;

		try {
			fOut = context.openFileOutput(file, Context.MODE_PRIVATE);
			osw = new OutputStreamWriter(fOut);
			osw.write(data);
			osw.flush();
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		} finally {
			try {
				osw.close();
				fOut.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return flag;
	}
}
